package com.zyz.forum_test;

import com.zyz.forum_test.core.Invitation;
import com.zyz.forum_test.core.User;
import com.zyz.forum_test.util.ScreenshotUtil;
import com.zyz.forum_test.util.WebDriverUtil;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;

public class Main {
    public static void main(String[] args) {

        Main main = new Main();
        main.testAll();
    }

    /**
     * 需提前删除xiaohong用户
     */
    public void testAll() {
        User user = new User();
        try {
            user.loginAndExit("admin","123456");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"loginAndExit");
            exception.printStackTrace();
            return;
        }

        try {
            user.register("xiaohong","lixiaohong","123456");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"register");
            exception.printStackTrace();
            return;
        }

        try {
            user.userHistoryPost("xiaohong","123456");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"userHistoryPost");
            exception.printStackTrace();
            return;
        }

        try {
            user.userCenter("C:\\Users\\Administrator\\Pictures\\254ae5683ddf901e6f436125719d261.jpg",
                    "xiaohonghong","123456","654321","3099677224@163.com","19000000001","这个是个人介绍...");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"userCenter");
            exception.printStackTrace();
            return;
        }

        Invitation invitation = new Invitation();
        try {
            invitation.addInvitation("admin","123456",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),"这是一个测试帖子");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"addInvitation");
            exception.printStackTrace();
            return;
        }

        try {
            invitation.editInvitation(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),"更改了帖子的内容");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"editInvitation");
            exception.printStackTrace();
            return;
        }

        try {
            invitation.siteMessage("xiaohong","654321","admin","123456","发送一条站内信");
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"siteMessage");
            exception.printStackTrace();
            return;
        }

        try {
            invitation.deleteInvitation();
        } catch (Exception exception) {
            ScreenshotUtil.screenshot(WebDriverUtil.getDriver(),"siteMessage");
            exception.printStackTrace();
            return;
        }finally {
            WebDriverUtil.quit();
        }
        System.out.println("----------------------");
        System.out.println("话题长廊测试完毕");

    }
}
